layui.use(['form','layer','table','util'],function (){
    let form = layui.form,layer = layui.layer,table = layui.table,util = layui.util;

    //监听table 工具栏，修改受理状态：档案数字化、数字化完成
    table.on('toolbar(fistDataTable)',function (obj) {

        //获取监听事件
        let layEvent = obj.event;
        //获取所有的选中的数据
        let companyData = layui.table.checkStatus("dataTableId").data;
        if (companyData.length <= 0){
            layer.msg("请选择一条数据",{icon:3,time:1500});
            return;
        }
        if (companyData.length > 1){
            layer.msg("一次只能选择一条数据",{icon:3,time:1500});
            return;
        }
        let jsonData = {
            "cmCreditCode" : companyData[0].cmCreditCode
        }
        sendAjax("/archivesMoveOut/moveIn",jsonData,function (res) {
            if (valueIsEqual(res.code,"00")){
                top.layer.msg("企业迁入成功",{icon:6,time:1500});
            }else {
                top.layer.msg("企业迁入失败！",{icon:6,time:1500});
            }
            queryArchivesMoveList();
        })
    });

    //监听 table 行内工具栏
    table.on('tool(fistDataTable)',function (obj) {
        let layEvent = obj.event;
        setValue("ciCreditCode",obj.data.cmCreditCode);
        if (valueIsEqual(layEvent,'showCompanyInfo')){
            top.layer.open({
                title:'查看企业所有卷信息',
                type:2,
                resize:false,
                area:['1200px','650px'],
                content: '/archivesMoveOut/showCompanyInfo',
                end:function (obj) {
                    //queryArchivesMoveList();
                }
            });
        }
    })
})

/**
 * @author: ChengJW
 * @params:
 * @return:
 * @date: 2021/9/22
 * @description: 初始化生成table数据
 */
$(function () {
    queryArchivesMoveList();
})

/**
 * @author: ChengJW
 * @params:
 * @return:
 * @date: 2021/9/22
 * @description: 生成table数据
 */
function queryArchivesMoveList() {

    //查询条件类型
    let srchReqFir = $("select[name = 'srchReqFir']").val();
    //查询条件
    let qryReqFir = $("input[name = 'qryReqFir']").val().trim();
    let jsonData = {
        "srchReqFir" : srchReqFir,
        "qryReqFir" : qryReqFir
    }
    //时间戳
    let tableTitle = '迁出企业信息表'+layui.util.toDateString(new Date(),'yyyyMMddHHmmss');
    layui.table.render({
        elem:'#dataTable',
        id:'dataTableId',
        url:'/archivesMoveOut/queryArchivesMoveInList',
        parseData:function (result) {
            return{
                "code":result.code,
                "msg":result.msg,
                "count":result.data.pageCount,
                "data":result.data.list
            }
        },
        size:'sm',
        //分页的起止页号，每页条数
        page:{
            curr:1,
            limit:15,
            limits:[15,30,50,100]
        },
        //自定义的页码参数名称、每页条数参数名称
        request:{
            pageName:'pageNum',
            limitName:'pageSize'
        },
        //table的高度
        height:500,
        //查询条件，json格式
        where:jsonData,
        cols:[[
            {type:'checkbox'},
            {type:'numbers',title:'序号'},
            {field:'cmRegistId',title:'注册号'},
            {field:'cmCreditCode',title:'统一社会信用代码'},
            {field:'cmNm',title:'企业名称',width:300},
            {field:'cmPripalNm',title:'法人'},
            {field:'cmMvOutNm',title:'迁出单位'},
            {field:'cmMvOutDt',title:'迁出日期',width:100,templet:function (d) {
                    return layui.util.toDateString(d.ciRegistDt,"yyyy-MM-dd");
                }},
            {field: '',title: '卷信息',align:'center',toolbar:'#toolBar'},
            {field:'cmMvOutCode',title:'迁出单位代码',hide:true}
        ]],
        //头部工具条
        toolbar: '#totalToolBar',
        //导出时候excel文件标题
        title:tableTitle
    });
}

/**
 * @author: ChengJW
 * @params:
 * @return:
 * @date: 2021/12/2
 * @description: 获取选中行的业务申请编号集合
 */
function getCiCreditCodeList(companyData) {
    let ciCreditCodeList = "";
    for (let i=0;i < companyData.length; i++){
        if (valueIsEqual(ciCreditCodeList,"")){
            ciCreditCodeList = companyData[i].ciCreditCode ;
        }else {
            ciCreditCodeList = ciCreditCodeList + "," + companyData[i].ciCreditCode;
        }
    }
    return ciCreditCodeList;
}